<?php
/**
 * Created by PhpStorm.
 * User: liaochungui
 * Email: liaodeity@foxmail.com
 * Date: 2017/11/18
 */

namespace App\Libs\Liao;


use App\Modules\Liaofield\Models\Liaofield;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

class LiaoDb
{
    protected $db_name    = '';
    protected $table_name = '';

    public function __construct()
    {
        $this->db_name = env ('DB_DATABASE');
    }

    public function setTableName($table_name)
    {
        $this->table_name = $table_name;

        return $this;
    }
    
    /**
     * 获取所有表名
     * @return mixed
     */
    public function getTables()
    {
        $sql  = "SELECT
                    TABLE_NAME AS table_name
                FROM
                    information_schema.`TABLES`
                WHERE
                    TABLE_SCHEMA = ?";
        $list = DB::select ($sql, [$this->db_name]);

        return $list;
    }

    public function getColumn()
    {
        $sql  = "SELECT
                    COLUMN_NAME AS col_name,
                    COLUMN_COMMENT AS col_comment,
                    DATA_TYPE AS data_type,
                    CHARACTER_MAXIMUM_LENGTH AS max_length
                FROM
                    information_schema.`COLUMNS`
                WHERE
                    TABLE_SCHEMA = ?
                AND TABLE_NAME = ?";
        $list = DB::select ($sql, [$this->db_name, $this->table_name]);

        return $list;
    }
}